package cn.le.beans.vo;

import cn.le.enums.EnumResponseCode;
import lombok.Data;

/**
 * @Description
 * @Author le
 * @Date 2020/2/16 12:49
 * @Version 0.1
 **/
@Data
public class ResponseVO<T> {

    /**
     * 返回码
     */
    private int code;
    /**
     * 提示信息
     */
    private String msg;
    /**
     * 返回数据
     */
    private T data;


    public static ResponseVO success(){
        return success("操作成功");
    }

    public static <T> ResponseVO success(String msg,T data){
        return new ResponseVO(EnumResponseCode.SUCCESS.getCode(),msg,data);
    }

    public static <T> ResponseVO success(String msg){
        return new ResponseVO(EnumResponseCode.SUCCESS.getCode(),msg,null);
    }

    public static <T> ResponseVO failed(String msg){
        return new ResponseVO(EnumResponseCode.FAILED.getCode(),msg,null);
    }

    public static <T> ResponseVO build(EnumResponseCode code){
        return new ResponseVO(code.getCode(),code.getMsg(),null);
    }

    public ResponseVO(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

}
